package org.acsis.jee.mail;


import javax.mail.*;

import org.apache.log4j.Logger;

/**
 *  Email User Authentification
 *
 *  @author Mohamed Cherb
 */
public class EMailAuthenticator extends Authenticator
{
	/**
	 * 	Constructor
	 * 	@param username user name
	 * 	@param password user password
	 */
	public EMailAuthenticator (String username, String password)
	{
		m_pass = new PasswordAuthentication (username, password);
		if (username == null || username.length() == 0)
		{
			log.info("Username is NULL");
			Thread.dumpStack();
		}
		if (password == null || password.length() == 0)
		{
			log.info("Password is NULL");
			Thread.dumpStack();
		}
	}	//	EMailAuthenticator

	/**	Password		*/
	private PasswordAuthentication 	m_pass = null;
	/**	Logger			*/
	private static Logger log = Logger.getLogger(EMailAuthenticator.class);

	/**
	 *	Ger PasswordAuthentication
	 * 	@return Password Autnetifucation
	 */
	@Override
	protected PasswordAuthentication getPasswordAuthentication()
	{
		return m_pass;
	}	//	getPasswordAuthentication

	/**
	 * 	Get String representation
	 * 	@return info
	 */
	@Override
	public String toString()
	{
		if (m_pass == null)
			return "EMailAuthenticator[]";
		if (log.isInfoEnabled())
			return "EMailAuthenticator[" 
				+ m_pass.getUserName() + "/" + m_pass.getPassword() + "]";
		return "EMailAuthenticator[" 
			+ m_pass.getUserName() + "/************]";
	}	//	toString

}	//	EMailAuthenticator
